
package com.ljt.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ljt.admin.entity.SysLog;
import com.ljt.common.security.annotation.Inner;
import com.ljt.common.utils.BaseResult;
import com.ljt.common.utils.BaseResultGenerator;
import com.ljt.service.SysLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 日志表 前端控制器
 * </p>
 *
 * @author administrator
 * @date 2019/07/25
 * @since 2019/2/1
 */
@Api(value = "日志管理", tags = {"日志管理"})
@RestController
@AllArgsConstructor
@RequestMapping("/log")
public class LogController {
	private final SysLogService sysLogService;

	/**
	 * 简单分页查询
	 *
	 * @param page   分页对象
	 * @param sysLog 系统日志
	 * @return
	 */
	@ApiOperation(value = "分页查询", notes = "作者：administrator")
	@GetMapping("/page")
	public BaseResult getLogPage(Page page, SysLog sysLog) {
		return BaseResultGenerator.success(sysLogService.page(page, Wrappers.query(sysLog)));
	}


	/**
	 * 插入日志
	 *
	 * @param sysLog 日志实体
	 * @return success/false
	 */
	@ApiOperation(value = "添加日志", notes = "作者：administrator")
	@Inner
	@PostMapping
	public BaseResult save(@Valid @RequestBody SysLog sysLog) {
		return BaseResultGenerator.success(sysLogService.save(sysLog));
	}

}
